// // src/api/user.ts
// import request from "@/request";

// interface SignInOptions {
//   username: string;
//   password: string;
//   remember?: boolean;
// }

// interface UserInfo {
//   id: number;
//   username: string;
//   avatar: string;
// }
// export const test = async (): Promise<string> => {
//   const data = await request({
//     url: "/test",
//     method: "GET",
//   });
//   return data;
// };
// export const signIn = async (options: SignInOptions): Promise<UserInfo> => {
//   const data = await request({
//     url: "/signIn",
//     method: "POST",
//     data: { ...options },
//   });
//   return data;
// };

// export const getUserInfo = async (userId: number): Promise<UserInfo> => {
//   const data = await request({
//     url: `/user/${userId}`,
//     method: "GET",
//   });
//   return data;
// };

// // 其他用户相关API...

// src/api/user.ts
import { post, get,put } from "@/request";
import router from "@/router";




interface UserInfo {
  id: number;
  username: string;
  nickname: string;
  avatar: string;
  // 其他用户信息字段
}
export const test = async (): Promise<string> => {
  return get<string>("/test");
};
export const signIn = async (options: any): Promise<UserInfo> => {
  return post<UserInfo>("/signIn", options);
};
export const register = async (options: any): Promise<any> => {
  return post<any>("/auth/register", options);
};
export const login = async (options: any): Promise<any> => {
  return post<any>("/auth/login", options);
};
// 验证Token有效性
export const verifyToken = async (): Promise<boolean> => {
  return get<boolean>("/auth/verifyToken");
};

// 登出接口
export const logout = async (): Promise<void> => {
  return post<void>("/auth/logout");
};

export const getCode = async (options: any): Promise<any> => {
  return post<any>("/auth/getCode", options);
};


export const updateRoom = async (options: any): Promise<any> => {
  return put<any>("/studyRoom/updateRoomConfig", options);
};
export const selectRoomConfig = async (options: any): Promise<any> => {
  return get<any>("/studyRoom/selectStudyRoomConfig", options);
};
//修改用户基础信息
export const updateUserInfo = async (options: any): Promise<any> => {
  return put<any>("/user/updateUserInfo", options);
};
//修改密码方法
export const updatePassword = async (options: any): Promise<any> => {
  return put<any>("/user/updatePassword", options);
};

export const uploadAvatar = async (formData: FormData) => {
  return post("/user/upload", formData, {
    headers: {
      "Content-Type": undefined  // 清除全局设置的 application/json
    }
  });
};

export const getUserInfo = async (userId): Promise<UserInfo> => {
  return post<UserInfo>(`/user/getUserInfo`, { userId });
};
// export const uploadAvatar = async (file: File): Promise<any> => {
//   const formData = new FormData();
//   formData.append("avatar", file);
//   return post<any>("/file/upload", formData);
// };

// 获取正常状态用户数
export const fetchTotalUsers = async (): Promise<any> => {
  return get<any>("/statistic/totalUserCount");
};

//修改用户社交信息
export const updateSocialInfo = async (data: any): Promise<any> => {
  return put<any>("/socialData/update", data);
};

// 获取用户社交信息
export const getSocialData = async (userId: number): Promise<any> => {
  return get<any>(`/socialData/${userId}`);
};
// 其他用户相关API...

export const getOnlineUser = async (): Promise<any> => {
  return get<any>("/statistic/onlineUser");
};
export const getRoomCount = async (): Promise<any> => {
  return get<any>("/statistic/activeRoom");
};